package com.example.minemodule.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.example.minemodule.R;
import com.example.minemodule.entity.MyDoctorBean;
import com.yilijk.base.utils.ClickUtils;

import java.util.List;

/**
 * Created by SHICHENG
 * <p>
 * Time on
 */
public class MyDoctorAdapter extends RecyclerView.Adapter<MyDoctorAdapter.MainViewHolder> {
    private List<MyDoctorBean.DataBean.MyDoctorVOListBean> datas;
    private Context mContext;
    private LayoutInflater mLiLayoutInflater;
    private AdapterItemChildClick adapterItemChildClick;

    public MyDoctorAdapter(List<MyDoctorBean.DataBean.MyDoctorVOListBean> datas, Context context) {
        this.datas = datas;
        this.mContext = context;
        this.mLiLayoutInflater = LayoutInflater.from(context);
    }

    @NonNull
    @Override
    public MainViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MainViewHolder(mLiLayoutInflater.inflate(R.layout.item_my_doctor,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull MainViewHolder holder, int position) {
        holder.item_name.setText(datas.get(position).getName());
        holder.item_job.setText(datas.get(position).getTitleName());
        holder.item_hospital.setText(datas.get(position).getHospitalName());
        holder.item_change.setVisibility(datas.get(position).isDrag()?View.VISIBLE:View.INVISIBLE);
        holder.item_hidden.setVisibility(datas.get(position).isShow()?View.INVISIBLE:View.VISIBLE);
        holder.item_menu.setVisibility(datas.get(position).isLeftShift()?View.VISIBLE:View.GONE);
        holder.item_s_h.setText(datas.get(position).isShow()?"隐藏":"显示");
        holder.item_s_h.setBackgroundResource(!datas.get(position).isShow()?R.drawable.style_mydoctor_item_hide_bg:R.drawable.style_mydoctor_item_show_bg);
        Glide.with(mContext).load(datas.get(position).getAvatar()).transform(new CenterCrop(),new CircleCrop()).into(holder.item_avator);
        holder.item_s_h.setOnClickListener(v -> {if (adapterItemChildClick!=null){adapterItemChildClick.click(holder.item_s_h,position);}});
        holder.item_doctor.setOnClickListener(v -> {if (adapterItemChildClick!=null){adapterItemChildClick.click(holder.item_doctor,position);}});
    }

    @Override
    public int getItemCount() {
        return datas !=null ? datas.size() : 0;
    }

    public class MainViewHolder extends RecyclerView.ViewHolder{
        TextView item_name;
        TextView item_job;
        TextView item_hospital;
        TextView item_s_h;
        ImageView item_avator;
        ImageView item_change;
        ImageView item_hidden;
        RelativeLayout item_doctor;
        LinearLayout item_menu;
        public MainViewHolder(@NonNull View itemView) {
            super(itemView);
            item_name = itemView.findViewById(R.id.item_mydoctor_name);
            item_job = itemView.findViewById(R.id.item_mydoctor_job);
            item_hospital = itemView.findViewById(R.id.item_mydoctor_hospital_room);
            item_s_h = itemView.findViewById(R.id.item_mydoctor_show_hidden);
            item_avator = itemView.findViewById(R.id.item_mydoctor_avator);
            item_change = itemView.findViewById(R.id.item_mydoctor_change_img);
            item_hidden = itemView.findViewById(R.id.item_mydoctor_hidden);
            item_doctor = itemView.findViewById(R.id.item_mydoctor);
            item_menu = itemView.findViewById(R.id.item_mydoctor_menu);
        }
    }


    public interface AdapterItemChildClick{

        void click(View view,int position);

    }

    public void setAdapterItemChildClick(AdapterItemChildClick adapterItemChildClick) {
        this.adapterItemChildClick = adapterItemChildClick;
    }
}
